<?php
/**
 * Created by PhpStorm.
 * User: liminfi
 * Date: 2017/3/10
 * Time: 18:04
 */
// 该代码块用于接收用户消息，根据用户输入的消息类型进行判断，文本，图片，视频，位置，链接，语音等，并取得值，处理后给予响应。
// 接收用户消息
// 微信公众账号接收到用户的消息类型判断
//

$wechatObj = new SQLop();
$conn=$wechatObj->connectSQL();
if($conn){
    $wechatObj->updateSQL($conn);
}
class SQLop
{
    public function updateSQL($conn)
    {
		$sqlname = $_POST['sqlname'];
		
		$rank = $_POST['rank'];
        $name = $_POST['name'];
		$win = $_POST['win'];
		$lose = $_POST['lose'];
		$month1 = $_POST['month1'];
		$month2 = $_POST['month2'];
        $score = $_POST['score'];
		$percent = $_POST['percent'];
		$count = $_POST['count'];
        $des = $_POST['Description'];


		//先查是否有
		$sql = "SELECT * FROM ".$sqlname." WHERE name='$name' AND rank='$rank'" ;
        $query = mysqli_query($conn, $sql);
		if ($query->num_rows > 0) {
			
			$sql = "UPDATE ".$sqlname." SET 
										rank='$rank',
										name='$name',
										win='$win',
										lose='$lose',
										month1='$month1',
										month2='$month2',
										score='$score',
										percent='$percent',
										count='$count',
										Description='$des' WHERE name='$name' AND rank='$rank'";
			$query = mysqli_query($conn, $sql);
			echo "更新球员 ".$name." 的数据";
			if ($query) {
				echo "成功";
			} else {
				echo "失败";
			}
		}else{
			echo "新建球员 ".$name." 数据";
			$sql = "INSERT INTO  ".$sqlname."(rank,name,win,lose,month1,month2,score,percent,count,Description) VALUES ("."
																			'$rank'
																			".","."
																			'$name'
																			".","."
																			'$win'
																			".","."
																			'$lose'
																			".","."
																			'$month1'
																			".","."
																			'$month2'
																			".","."
																			'$score'
																			".","."
																			'$percent'
																			".","."
																			'$count'
																			".","."
																			'$des'
																			)";
			if(mysqli_query($conn, $sql))echo "成功";
			else echo "失败";
		}
    }

    public function connectSQL()
    {
        $servername = "localhost";
        $username = "root";
        $password = "";

// 创建连接
        $conn = mysqli_connect($servername, $username, $password, 'wx');
		$conn->query("SET NAMES utf8");
        return $conn;
    }
}